# -*- coding: utf-8 -*-
"""
@Time    : 2024/8/20 11:02 
@Author  : ZhangShenao 
@File    : 4.一切皆对象.py 
@Desc    : 一切皆对象

在Python中,一切皆对象
所有内置的类型,如list、tuple、str、int等,本质上都是对象,都可以通过属性和方法进行操作
"""


class Dog(object):
    # 类属性

    leg_num: int = 4
    has_hair: bool = True
    has_tail: bool = True

    def __init__(self, name: str, breed: str, age: int):
        """
        构造方法
        :param name: 狗的名字
        :param breed: 狗的品种
        :param age: 狗的年龄
        """

        # 初始化实例属性
        print("执行__init__构造方法")
        self.name = name
        self.breed = breed
        self.age = age

    # 定义实例方法

    def bark(self):
        print(f"{self.name}正在旺旺叫...")

    def eat(self):
        print(f"{self.name}正在吃东西...")

    def play(self):
        print(f"{self.name}正在玩耍...")

    def show_info(self):
        print(f"小狗的名字: {self.name}, 品种: {self.breed}, 年龄: {self.age}")


i = 10
# i = int(10)   # 这两种声明方式是等价的
# type of i is <class 'int'>, value is 10
print(f"type of i is {type(i)}, value is {i}")

s = "abc"
# s = str("abc")    # 这两种声明方式是等价的
# type of s is <class 'str'>, value is abc
print(f"type of s is {type(s)}, value is {s}")

l = list([1, 2, 3])
# l = list(1, 2, 3)  # 这两种声明方式是等价的
# type of l is <class 'list'>, value is [1, 2, 3]
print(f"type of l is {type(l)}, value is {l}")

# 通过自定义类创建的对象,它的类型就是自定义类本身
d = Dog("小黑", "秋田犬", 3)
# type of d is <class '__main__.Dog'>, value is <__main__.Dog object at 0x103c2ca70>
print(f"type of d is {type(d)}, value is {d}")

# 自定义的类对象,属于可变类型(Mutable),可以修改其属性
d.name = "小花"
d.show_info()

# 实例对象也是一等公民:可以作为变量传递、作为函数参数,也可以作为函数返回值
